package cn.edu.lingnan.controller;
import cn.edu.lingnan.dao.VacMapper;
import cn.edu.lingnan.pojo.Country;
import cn.edu.lingnan.pojo.Vac;
import cn.edu.lingnan.service.VacService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;
import java.util.List;

@Controller
@RequestMapping("/vac")
public class VacController {

    @Autowired
    @Qualifier("vacService")
    private VacService vacService;


    @RequestMapping("/selectVacAll")
    // 查找所有的疫苗信息
    public String findAllVac(Model model){
        model.addAttribute("allVac",vacService.findAllVac());
//        System.out.println();
        return "admin/allVac";
    }

    @RequestMapping("/insertInfoToVac")
    //新增一条疫苗信息
    public String insertVac(Vac vac) {
        vacService.insertInfoToVac(vac);
        return "redirect:/vac/selectVacAll";//这里应该跳转到查询所有页面
    }
    @RequestMapping("/updateVacInfoByVacId")
    public String updateVacInfoByVacId(Vac _id){
        vacService.updataVac(_id);
        return "redirect:/vac/selectVacAll";
    }
    @RequestMapping("/toUpdateVacInfoByVacId")
    public String toUpdateVacInfoByVacId(int vac_id,Model model){
        Vac vac = vacService.findVacByVac_id(vac_id);
        model.addAttribute("vac",vac);
        return "admin/updateVac";
    }
    @RequestMapping("/deleteVacByVac_id")
    public String deleteVacByVac_id(int vac_id) throws SQLException {
        if((vacService.findVacByVac_idIfInC_V(vac_id))==null){
            vacService.deleteVac(vac_id);
        }
        return "redirect:/vac/selectVacAll";
    }
}
